<template>
    <div>
        <el-row>
            <el-col :span="24" class="base-mian-cell" v-if="IDFlag">
                <div class="base-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">个人税收居民身份证明</span>
                    </div>
                    <div class="right fr" @click="changeView">
                        <i class="el-icon-circle-close"></i>
                    </div>
                </div>
                <div class="base-mian-cell-main editInput">
                    <el-row class="mb10">
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">姓名(投保人):</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.calname"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="5">
                            <label class="complain-lab">本人声明:</label>
                        </el-col>
                        <el-col :span="19">
                                <el-radio :disabled="allInfoReadOnly" v-model="tax.pflag" label="1">1、仅为中国税收居民</el-radio>
                                <el-radio :disabled="allInfoReadOnly" v-model="tax.pflag" label="2">2、仅为非居民</el-radio>
                                <el-radio :disabled="allInfoReadOnly" v-model="tax.pflag" label="3">3、既是中国税收居民又是其他国家(地区)税收居民</el-radio>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">&nbsp;</el-col>
                        <el-col :span="19">
                            <label class="tips-txt">如以上选项中勾选2项或第3项，请填写下列信息：</label>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="8">
                            <el-col :span="6">
                                <label class="complain-lab">姓(英文或拼音)</label>
                            </el-col>
                            <el-col :span="18">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.susrname"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="6">
                                <label class="complain-lab">名(英文或拼音)</label>
                            </el-col>
                            <el-col :span="18">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.susrgname"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="8">
                            <el-col :span="6">
                                <label class="complain-lab">出生日期</label>
                            </el-col>
                            <el-col :span="18">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.smoddate"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                </div>
                <div class="app-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">现居住地(境外地址无需填写中文地址栏)：</span>
                    </div>
                </div>
                <div class="base-mian-cell-main editInput">
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">中文栏:</label>
                        </el-col>
                        <el-col :span="19">
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">国家</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.nationdc"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">省</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.sprovname"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">市</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.scityname"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">现居详细地址</label>
                        </el-col>
                        <el-col :span="19">
                            <el-input v-model="tax.lngaddr01" :disabled="allInfoReadOnly"></el-input>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">英文栏:</label>
                        </el-col>
                        <el-col :span="19">
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">国家</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.nationabdc"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">省</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.pprovname"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">市</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.pcityname"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">出生地详细地址</label>
                        </el-col>
                        <el-col :span="19">
                            <el-input :disabled="allInfoReadOnly" v-model="tax.lngaddr02"></el-input>
                        </el-col>
                    </el-row>
                </div>

                <div class="app-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">出生地(境外地址无需填写中文地址栏)：</span>
                    </div>
                </div>

                <div class="base-mian-cell-main editInput">
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">中文栏:</label>
                        </el-col>
                        <el-col :span="19">
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">国家</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.cntname"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">省</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.provname"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">市</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.city"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">现居详细地址</label>
                        </el-col>
                        <el-col :span="19">
                            <el-input :disabled="allInfoReadOnly" v-model="tax.lngaddr03"></el-input>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">英文栏:</label>
                        </el-col>
                        <el-col :span="19">
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">国家</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.crname"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">省</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.prodesc"></el-input>
                                </el-col>
                            </el-col>
                            <el-col :span="8">
                                <el-col :span="6">
                                    <label class="complain-lab">市</label>
                                </el-col>
                                <el-col :span="18">
                                    <el-input :disabled="allInfoReadOnly" v-model="tax.citydesc"></el-input>
                                </el-col>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">
                            <label class="complain-lab">出生地详细地址</label>
                        </el-col>
                        <el-col :span="19">
                            <el-input :disabled="allInfoReadOnly" v-model="tax.lngaddr04"></el-input>
                        </el-col>
                    </el-row>
                </div>

                <div class="app-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">税收居民国(地区)及纳税人居民号：</span>
                    </div>
                </div>

                <div class="base-mian-cell-main editInput">
                    <el-row class="mb10">
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">税收居民国(地区)1</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.sdesc01"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">纳税人识别号1</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.pedesc01"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">税收居民国(地区)2</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.sdesc02"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">纳税人识别号2</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.pedesc02"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">税收居民国(地区)3</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.sdesc03"></el-input>
                            </el-col>
                        </el-col>
                        <el-col :span="12">
                            <el-col :span="10">
                                <label class="complain-lab">纳税人识别号3</label>
                            </el-col>
                            <el-col :span="14">
                                <el-input :disabled="allInfoReadOnly" v-model="tax.pedesc03"></el-input>
                            </el-col>
                        </el-col>
                    </el-row>
                    <el-row class="mb10">
                        <el-col :span="5">&nbsp;</el-col>
                        <el-col :span="19">
                            <label class="">如不能提供居民国(地区)信息，纳税人识别号，请选择原因：</label>
                        </el-col>
                    </el-row>

                    <el-row class="mt10">
                        <el-col :span="5">&nbsp;</el-col>
                        <el-col :span="19">
                                <el-radio :disabled="allInfoReadOnly" v-model="tax.reasons" label="居民国(地区)不发纳税人识别号"></el-radio>
                                <el-radio :disabled="allInfoReadOnly" v-model="tax.reasons" label="账户持有人未能取得纳税人识别号，如此选项，请解释具体原因"></el-radio>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="5">&nbsp;</el-col>
                        <el-col :span="19">
                            <el-input :disabled="allInfoReadOnly"
                                    type="textarea"
                                    :rows="2"
                                    placeholder="请输入内容"
                                    v-model="tax.pareason">
                            </el-input>
                        </el-col>
                    </el-row>

                </div>
                <div class="edit-main" v-if="!allInfoReadOnly">
                    <button @click="saveInfo">保存</button>
                </div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
  import {
    queryIndividualTax,
    updateIndividualTax,
    checkWDfor400
  } from "@/api/underwriting/uw";
  import appName from '@/api/appName';
  import {getToken,setCookie} from '@/utils/auth';
  import constant from '@/utils/constant';

  export default {
    data() {
      return {
        checkList: [],
        textarea: '',
        tax: {
          "clntnum":"",
          "chdrnum":"",
          "serno":"",
          "appfrom":"",
          "dtecrt":"",
          "datime":"",
          "pflag":"",
          "calname":"",
          "susrname":"",
          "susrgname":"",
          "smoddate":"",
          "nationdc":"",
          "nationabdc":"",
          "sprovname":"",
          "pprovname":"",
          "scityname":"",
          "pcityname":"",
          "lngaddr01":"",
          "lngaddr02":"",
          "cntname":"",
          "crname":"",
          "provname":"",
          "prodesc":"",
          "city":"",
          "citydesc":"",
          "lngaddr03":"",
          "lngaddr04":"",
          "sdesc01":"",
          "sdesc02":"",
          "sdesc03":"",
          "pedesc01":"",
          "pedesc02":"",
          "pedesc03":"",
          "reasons":"",
          "pareason":"",
          "job_name":"",
          "userProfile":"",
        },
        procflg:"",
        oprationType:false
      }
    },
    props: {
      IDFlag: {
        type: Boolean,
        default: false
      },
      allInfoReadOnly: {
        type: Boolean,
        default: false
      },
      applnum: {
        type: String,
        default: ""
      },
      clntnum: {
        type: String,
        default: ""
      },

    },
    mounted() {
      console.log(this.appIDFlag);
    },
    methods: {
      changeView() {
        this.$emit('subIDFlag', false);
      },
      //个人税收
      showTax() {
        let that = this;
        let params = {
          "appfrom": "EU",
          "applnum": this.applnum,
          "clntnum": this.clntnum
        }
        that.$emit('showLoading',true);
        queryIndividualTax(params).then(res => {
          that.$emit('showLoading',false);
          if (res.resultCode == constant.SUCCESS && res.data != null) {
            if(res.data.IndividualTaxPO){
              that.tax = res.data.IndividualTaxPO;
            }
          }
        }).catch(err => {
          console.log(err)
        })

        let params1 = {
          "applnum":this.applnum
        }
        this.$.ajax({
          headers: {
            Authorization: getToken(constant.TOKEN) || ''
          },
          url: appName.NEWUNDR + '/unipnd/nucleusNote/findProcflgFromEuaapky',//url路径
          type: 'POST', //GET
          async: false, //或false,是否异步
          data: JSON.stringify(params1),
          contentType: "application/json;charset=UTF-8",
          success: function (res, textStatus, jqXHR) {
            if (res.resultCode == constant.SUCCESS && res.data != null) {
              that.procflg = res.data;
            }
          }
        })

        if (Number(this.procflg) > 4) {
          this.oprationType = true;
        }
      },

      popMsg(msg,type){
        this.$message({
          message: msg,
          type: type
        });
      },

      async check400(){
        let procflg = "";
        let params = {
          "applnum":this.applnum
        }
        await checkWDfor400(params).then(res => {
          if (res.resultCode == constant.SUCCESS) {
            procflg = res.data;
          }
        }).catch(err => {

        })
        return procflg;
      },
      async saveInfo(){
        let that = this;
        let procflg = await this.check400();
        if(procflg){
          if(procflg=="4" || procflg=="5" || procflg=="6"){
            that.popMsg("保单400状态为"+procflg+",请核实",'error');
            return false;
          }
        }

          if(this.tax.reasons == "2" && this.tax.pareason==""){
            this.popMsg("账户持有人未能取得纳税人识别号，请填写具体原因","error");
            return;
          }
          if(this.tax.nationdc=="" && this.tax.sprovname=="" && this.tax.scityname=="" && this.tax.lngaddr01==""){

          }else{
            if(this.tax.nationdc=="" || this.tax.sprovname=="" || this.tax.scityname=="" || this.tax.lngaddr01==""){
              this.popMsg("(中文)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空","error");
              return;
            }
          }

          if(this.tax.nationabdc=="" && this.tax.pprovname=="" && this.tax.pcityname=="" && this.tax.lngaddr02==""){

          }else{
            if(this.tax.nationabdc=="" || this.tax.pprovname=="" || this.tax.pcityname=="" || this.tax.lngaddr02==""){
              this.popMsg("(英文或拼音)现居住地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空","error");
              return;
            }
          }

          if(this.tax.cntname=="" && this.tax.provname=="" && this.tax.city=="" && this.tax.lngaddr03==""){

          }else{
            if(this.tax.cntname=="" || this.tax.provname=="" || this.tax.city=="" || this.tax.lngaddr03==""){
              this.popMsg("(中文)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空","error");
              return;
            }
          }

          if(this.tax.crname=="" && this.tax.prodesc=="" && this.tax.citydesc=="" && this.tax.lngaddr04==""){

          }else{
            if(this.tax.crname=="" || this.tax.prodesc=="" || this.tax.citydesc=="" || this.tax.lngaddr04==""){
              this.popMsg("(英文或拼音)出生地的国家、省、市和详细地址全都不能为空,除非单条记录全部为空","error");
              return;
            }
          }
          if(!this.tax.clntnum){
            this.tax.clntnum = this.clntnum;
          }


          let params = {
            "tax":JSON.stringify(this.tax),
            "appfrom": "EU",
            "applnum": this.applnum,
            "clntnum": this.clntnum
          }
          that.$emit('showLoading',true);
          updateIndividualTax(params).then(res=>{
            that.$emit('showLoading',false);
            if (res.resultCode == constant.SUCCESS) {
              this.popMsg("保存成功","success")
            }else{
              this.popMsg(res.resultMsg,"error")
            }

          }).catch(err=>{
            console.log(err);
          })

      },
    },
    created() {
      this.showTax();
    }
  }
</script>
<style lang="less" scoped>
    .check-group {
        height: 28px;
        line-height: 28px;
        overflow: hidden;
    }

    .tips-txt {
        color: #F76565;
    }

    .app-mian-cell-title {
        margin: 0 20px;
        height: 50px;
        line-height: 50px;
        background: #f8f8f8;
        padding: 0 20px;

        .left {
            .line {
                color: #f76767;
            }

            .tips {
                margin-left: 15px;
            }
        }
    }
</style>